#include <btBulletCollisionCommon.h>
#include <btBulletDynamicsCommon.h>

#include <OgreSceneNode.h>

#include "Core.h"
#include "GameObj.h"


using namespace pong;

GameObject::GameObject(Core& c, Ogre::SceneNode* const node,
                       btRigidBody* const rigidBody)
    : core(c),
	  body(rigidBody)
{
	core.renderer()->addFrameListener(this);
    renderNode = node->createChildSceneNode();
}

GameObject::~GameObject(void) {
	renderNode->getCreator()->destroySceneNode(renderNode);
	core.renderer()->removeFrameListener(this);
}

bool GameObject::frameStarted(const Ogre::FrameEvent& e) {
    const btVector3& pos = body->getCenterOfMassPosition();
    const btQuaternion rot = body->getOrientation();
    renderNode->setPosition(pos.x(), pos.y(), pos.z());
    renderNode->setOrientation(rot.w(), rot.x(), rot.y(), rot.z());
	return true;
}
